package tables

import (
	"peilian-api/app/global/variable"
)

type School struct {
	Model
	Name string `gorm:"type:varchar(100);comment:学校名称" json:"name"`
}

func (s *School) TableName() string {
	return "school"
}

// 查询学校
func (s *School) GetSchoolByQuery(query string) (out []string) {
	if len(query) == 0 {
		return out
	}
	if query == "全部" {
		variable.DB.MySQL.Model(&s).Select("name").Find(&out)
		return
	}
	variable.DB.MySQL.Model(&s).Select("name").Where("name like ?", "%"+query+"%").Find(&out)
	return out
}

// 查询学校
func (s *School) GetSchoolByName(name string) (out []*School) {
	if len(name) == 0 {
		return out
	}
	variable.DB.MySQL.Model(&s).Select("name").Where("name = ?", name).Find(&out)
	return out
}
